package cn.tedu.travelsystem.base.exception;

import cn.tedu.travelsystem.base.response.JsonResult;
import cn.tedu.travelsystem.base.response.StatusCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理频繁访问的异常
    @ExceptionHandler(AccessLimitException.class)
    public JsonResult handleAccessLimitException(AccessLimitException ex) {
        return new JsonResult(StatusCode.REQUEST_TOO_FREQUENT, ex.getMessage()); // 返回频繁访问错误
    }

    // 全局异常处理
    @ExceptionHandler(Exception.class)
    public JsonResult handleException(Exception ex) {
        return new JsonResult(StatusCode.INTERNAL_SERVER_ERROR, "系统异常: " + ex.getMessage()); // 处理其他异常
    }
}
